home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_217 / echo / echo / echo.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  190 lines

  1. /***********************************************\
  2.  *  Echo   -   just a small echo-replacement   *
  3.  *             with some enhancements I've     *
  4.  *             wrote 2 years ago.              *
  5. \***********************************************/
  6.  
  7. /* This program is *NOT* public domain, but may be copied and distributed on
  8.    a not-for-profit manner. It may be included in Fred's library. Any other
  9.    'Library-Creators' must ask me before including this program on their
  10.    disk (I hate to do that, but there are so many people over here in germany
  11.    that make people pay 10 Marks for some disks, half-full, and with programs
  12.    they take from other disks...)
  13.    Send any bug-reports, letters of appreciation, Porsche 911 or other small
  14.    gifts to the following address: (and I'd really like to know what WBSize
  15.    does on a NTSC Amy...)
  16.    
  17.    Garry Glendown
  18.    Güldene Kammer 35
  19.    6430 Bad Hersfeld
  20.    West Germany
  21.    
  22.    Or for the people lucky enough to get to some Bitnet or Usenet node:
  23.    
  24.    Garry@DGIHRZ01.BITNET
  25.                                                                     */
  26.  
  27.  
  28. #include <exec/types.h>
  29.  
  30. int t,g;
  31. BYTE flag;
  32.  
  33. UBYTE code[][9]={
  34.     {12,0},                /*Clear*/
  35.     {0x9b,0x4a,0},            /*ClrEOD*/
  36.     {0x9b,1,0x53,0},
  37.     {0x9b,1,0x54,0},        /*Scroll up/down*/
  38.     {0x9b,1,0x41,0},
  39.     {0x9b,1,0x42,0},        /*Cursor up/down*/
  40.     {0x9b,1,';',1,0x48,0},        /*Cursor x/y*/
  41.     {0x9b,1,';',1,';',1,0x6d}    /*Style*/
  42.     };
  43.  
  44. char st[]={'p','b',0xfe,'i','u'};
  45.  
  46. char **arv;
  47. int arc;
  48.  
  49. /* Attention! If the C-Compiler you use splits the CLI-Argument "The Test"
  50.    into two arguments, you'll have to leave this routine in the program.
  51.    If it returns the string `The Text' as one argument, take it out!
  52.    (=Aztec 3.4, probably 3.6, too)     */
  53. String()
  54. {
  55. char y[256];
  56. int g,j;
  57.     y[0]='\0';
  58.     if (arv[t][strlen(arv[t])-1]!='\"') {
  59.         strcat(y,&arv[t][1]);
  60.         do {
  61.             strcat(y," ");
  62.             strcat(y,arv[++t]);
  63.         }
  64.         while (arv[t][strlen(arv[t])-1]!='\"'&&t<arc);
  65.     }
  66.     else strcat (y,&arv[t][1]);
  67.     y[strlen(y)-1]='\0';
  68.     printf("%s\n",y);
  69.     flag=1;
  70. }
  71.  
  72.  
  73. main(argc,argv)
  74. int argc;
  75. char *argv[];
  76. {
  77. arv=argv;
  78. arc=argc;
  79. if (argc==1) help();
  80.     for (t=1;t<argc;t++) {
  81.         flag=0;
  82.         if (argv[t][0]=='-') Decode();
  83.         if (argv[t][0]=='"') String();    /* cut this out when using Aztec 3.4 */
  84.                                         /* (see above...) */
  85.         if (!flag) printf("%s\n",argv[t]);
  86.     }
  87. }
  88.  
  89. Decode()
  90. {
  91. int i,j[3];
  92. char c;
  93.     c=arv[t][1];
  94.     for (i=0;i<3;j[i++]=-1);
  95.     switch (c) {
  96.         case 'c':
  97.             putcode(0,&j);
  98.             break;
  99.         case 'e':
  100.             putcode(1,&j);
  101.             break;
  102.         case 'u':
  103.         case 'd':
  104.         case 'h':
  105.         case 'r':
  106.             j[0]=getvalue();
  107.             if (j[0]==-1) j[0]=1;
  108.             switch (c) {
  109.                 case 'u':
  110.                     putcode(2,&j);
  111.                     break;
  112.                 case 'd':
  113.                     putcode(3,&j);
  114.                     break;
  115.                 case 'h':
  116.                     putcode(4,&j);
  117.                     break;
  118.                 case 'r':
  119.                     putcode(5,&j);
  120.                     break;
  121.             }
  122.             break;
  123.         case 'p':
  124.             j[1]=getvalue();
  125.             if (j[1]==-1) j[1]=1;
  126.             j[0]=getvalue();
  127.             putcode(6,&j);
  128.             break;
  129.         case 's':
  130.             j[2]=0;
  131.             for (i=0;i<=4;i++) if (arv[t][2]==st[i]) j[2]=i;
  132.             code[7][1]=j[2]+0x30;
  133.             j[0]=getvalue();
  134.             if (j[0]==-1) j[0]=1;
  135.             j[0]+=30;
  136.             j[1]=getvalue();
  137.             if (j[1]==-1) j[1]=0;
  138.             j[1]+=40;
  139.             putcode(7,&j);
  140.             break;
  141.     }
  142.     flag=1;
  143. }
  144.  
  145. putcode(n,a)
  146. int n,*a;
  147. {
  148. int g,z=0;
  149.     for (g=0;g<7;g++) {
  150.         if (code[n][g]==0) g=10;
  151.         else {
  152.             if (code[n][g]==1) {senddigit(a[z]);z++;}
  153.             else putchar(code[n][g]);
  154.         }
  155.     }
  156. }
  157.  
  158. senddigit(val)
  159. int val;
  160. {
  161.     if (val!=-1) printf("%d",val);
  162. }
  163.  
  164. int getvalue()
  165. {
  166. int g,h;
  167.     g=sscanf(arv[t+1],"%d",&h);
  168.     if (g==-1) {h=-1;t--;}
  169.     t++;
  170.     return(h);
  171. }
  172.  
  173.  
  174. help()
  175. {
  176. printf("*** Echo ***\n");
  177. printf("© 1987-9 by G.Glendown\n");
  178. printf("Options:\n");
  179. printf("-c        Clear the screen\n");
  180. printf("-e        delete from cursor to bottom of screen\n");
  181. printf("-u/d [n]  scroll up/down [n] Lines\n");
  182. printf("-h/r [n]  move cursor up(h) or down(r) [n] lines\n");
  183. printf("-p [x][y] set cursor to postion [x][y]\n");
  184. printf("-s[ubip] [a][b]  Style u,b,i,p, colors [a][b]\n\n");
  185. exit();
  186. }
  187.  
  188.  
  189.  
  190.